
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>消息等待机制实现 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>消息等待机制实现 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是长轮询（Long Polling）？它与传统轮询有何核心区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">长轮询是一种特殊的轮询方式。当服务端没有可用数据时，它不会立即返回空结果，而是会保持连接一段时间。如果在等待期间有新数据可用，服务端会立即响应；如果等待超时仍无数据，则返回空结果。其与传统轮询的核心区别在于，传统轮询无论服务端是否有新数据都会立即响应，而长轮询在无数据时会挂起请求，从而减少了无效请求。</div>
          </div>
          <div class="card-source">来源: 长轮询的基本概念</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在RocketMQ中，当消费者发起拉取请求但Broker没有新消息时，长轮询机制是如何运作的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当消费者通过PullConsumer向Broker发送拉取请求但没有新消息时，Broker会挂起该请求，不立即返回空响应。Broker会等待，直到有新消息到达或等待超时（由`brokerSuspendMaxTimeMillis`参数控制），才会对该请求作出响应。</div>
          </div>
          <div class="card-source">来源: RocketMQ中的长轮询实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">RocketMQ Broker中`PullRequestHoldService`的核心职责是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`PullRequestHoldService`是Broker中专门处理挂起拉取请求的服务。其核心职责包括：1. 维护一个按Topic和QueueId组织的请求映射表；2. 定期检查是否有新消息到达，并通知对应的挂起请求；3. 处理请求超时，确保请求不会被无限期挂起。</div>
          </div>
          <div class="card-source">来源: RocketMQ中的长轮询实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">根据文档，使用长轮询机制能带来哪些主要优势？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">长轮询机制的主要优势包括：1. 降低网络开销：减少无效轮询，节省带宽和服务器资源。2. 提高实时性：新消息到达时能立即响应，减少消息延迟。3. 简化实现：基于请求-响应模型，无需维护复杂长连接。4. 提高可靠性：客户端主动发起请求，可以控制频率并感知服务端故障。</div>
          </div>
          <div class="card-source">来源: 长轮询的优势</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在RocketMQ的长轮询实现中，哪个关键参数定义了Broker挂起请求的最长时间，其默认值是多少？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">关键参数是 `brokerSuspendMaxTimeMillis`，它定义了Broker挂起拉取请求的最大时间。根据文档，其默认值为15秒。</div>
          </div>
          <div class="card-source">来源: RocketMQ中的长轮询实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">RocketMQ提供了哪几种消息拉取模式以适应不同场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">RocketMQ提供了三种消息拉取模式：1. 同步拉取（`pullBlockIfNotFound`）：消费者阻塞等待Broker响应，适用于顺序要求严格的场景。2. 异步拉取（`pullAsync`）：通过回调处理响应，不阻塞，适用于高吞吐量场景。3. 流式拉取：在异步基础上维护请求流水线，适用于超高吞吐量场景。</div>
          </div>
          <div class="card-source">来源: 消息拉取的等待策略 -> 拉取模式分类</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
